package cn.SiFuLan.controls;

import cn.SiFuLan.dao.IskuDao;
import cn.SiFuLan.dao.impl.skuDaoImapl;
import cn.SiFuLan.entity.skuEntity;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

@WebServlet(urlPatterns = "/admin/qwe")
public class skuaddServlt extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        skuEntity skuEntity=new skuEntity();
        String spu_id=request.getParameter("spu");
        if(spu_id!=null && !spu_id.equals("")){
            skuEntity.setSpu_id(Integer.parseInt(spu_id));
        }
        request.setAttribute("spu_id",spu_id);
        request.getRequestDispatcher("skuinsert.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        IskuDao iskuDao=new skuDaoImapl();
        skuEntity skuEntity=new skuEntity();
        String spu_id=request.getParameter("spuid");
        if(spu_id!=null && !spu_id.equals("")){
            skuEntity.setSpu_id(Integer.parseInt(spu_id));
        }
        String title=request.getParameter("title");
        String color=request.getParameter("color");
        String gg=request.getParameter("gg");
        String jg=request.getParameter("jg");
        String sf=request.getParameter("sf");
        skuEntity.setAddTime(new Date());
        skuEntity.setUpdateTime(null);
        skuEntity.setTitle(title);
        skuEntity.setColor(color);
        skuEntity.setSpecification(gg);
        skuEntity.setPrive(jg);
        if(sf!=null && !sf.equals("")){
            skuEntity.setValid(Integer.parseInt(sf));
        }
        iskuDao.add(skuEntity);
        request.getRequestDispatcher("skuindex.do").forward(request,response);
    }

}
